home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CSCROLLL
/
CSCROLLL.C
< prev
next >
Wrap
Text File
|
1992-02-19
|
4KB
|
168 lines
/*************************************************************************************
CScrollListDragger.c
Used with scrolling lists that allow the movement of array elements
within the list.
SUPERCLASS = CMouseTask
by Dave Harkness
*************************************************************************************/
#include "CScrollListDragger.h"
#include "CScrollList.h"
#include "CArray.h"
#include "TBUtilities.h"
/******************************************************************************
IScrollListDragger
Initialize a CScrollListDragger. theModifers should be the modifier flags
from DoClick. selFlags should be the table's selection flags.
******************************************************************************/
void
CScrollListDragger::IScrollListDragger( CScrollList *aTable,
short theModifiers, long selFlags)
{
CMouseTask::IMouseTask( 0);
itsTable = aTable;
itsArray = (CArray *)itsTable->GetArray();
selectionFlags = selFlags;
modifierKeys = theModifiers;
SetCell( movingCell, 0, 0);
} /* CScrollListDragger::IScrollListDragger */
/******************************************************************************
Dispose
Dispose of a CScrollListDragger. This method clears the table's reference to
this task.
******************************************************************************/
void
CScrollListDragger::Dispose(void)
{
if (itsTable->itsLastTask == this)
itsTable->itsLastTask = NULL;
inherited::Dispose();
}
/******************************************************************************
BeginTracking {OVERRIDE}
Called at the start of mouse tracking. This method selects the cell
being dragged and calculates the rectangle to drag.
******************************************************************************/
void CScrollListDragger::BeginTracking( LongPt *startPt)
{
Cell aCell;
LongRect aBounds;
Rect qdRect;
itsTable->FindHitCell( startPt, &aCell);
itsTable->SelectCell( aCell, FALSE, TRUE);
movingCell = aCell;
itsTable->GetCellRect( aCell, &dragRect);
OffsetLongRect( &dragRect, 0, startPt->v - ((dragRect.top + dragRect.bottom) >> 1));
itsTable->GetBounds( &aBounds);
SetLongRect( &clipRect, dragRect.left, aBounds.top, dragRect.right, aBounds.bottom);
itsTable->FrameToQDR( &dragRect, &qdRect);
PenPat( gray);
PenMode( patXor);
FrameRect( &qdRect);
} /* CScrollListDragger::BeginTracking */
/******************************************************************************
KeepTracking {OVERRIDE}
Called continously while the mouse button is held down. This method
continously draws a gray rectangle and autoscrolls the table.
******************************************************************************/
void
CScrollListDragger::KeepTracking(LongPt *currPt, LongPt *prevPt, LongPt *startPt)
{
long curTicks;
Rect qdRect;
PinInRect( &clipRect, prevPt);
PinInRect( &clipRect, currPt);
if (currPt->v != prevPt->v)
{
itsTable->FrameToQDR( &dragRect, &qdRect);
PenPat( gray);
PenMode( patXor);
for ( curTicks = TickCount(); curTicks == TickCount(); )
/* try to avoid flicker */ ;
FrameRect( &qdRect);
itsTable->AutoScroll( currPt);
OffsetLongRect( &dragRect, 0, currPt->v - prevPt->v);
itsTable->FrameToQDR( &dragRect, &qdRect);
PenPat( gray);
PenMode( patXor);
for ( curTicks = TickCount(); curTicks == TickCount(); )
/* try to avoid flicker */ ;
FrameRect( &qdRect);
}
} /* CScrollListDragger::KeepTracking */
/******************************************************************************
EndTracking {OVERRIDE}
Erase the dragging rectangle.
******************************************************************************/
void
CScrollListDragger::EndTracking(LongPt *currPt, LongPt *prevPt, LongPt *startPt)
{
Rect qdRect;
Cell endCell;
Str255 str;
itsTable->FrameToQDR( &dragRect, &qdRect);
PenPat( gray);
PenMode( patXor);
FrameRect( &qdRect);
itsTable->FindHitCell( currPt, &endCell);
if ( currPt->v - itsTable->GetRowStart( endCell.v) >=
itsTable->GetRowHeight( endCell.v) >> 1 )
++endCell.v;
if ( endCell.v > movingCell.v)
--endCell.v;
if ( endCell.v != movingCell.v )
{
itsArray->MoveItemToIndex( movingCell.v+1, endCell.v+1);
itsTable->SelectCell( endCell, FALSE, TRUE);
// itsTable->DoCommand( cmdMakeMeDirty);
}
} /* CScrollListDragger::KeepTracking */